package com.hfi.alibaba.timertask;

import org.junit.Test;

/**
 * @author ChangLiang
 * @date 2019/7/2
 */
public class ThreadTaskTest {

    static long count = 0;

    @Test
    public void test(){
        Runnable runnable = () -> {
            while (true) {
                try {
                    Thread.sleep(2000L);
                    // 模拟每个两秒触发的定时任务
                    count++;
                    System.out.println(count);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        };
        Thread thread = new Thread(runnable);
        thread.start();

        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
